import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/busOutsourcingPurchaseReturn/list',
  save='/busOutsourcingPurchaseReturn/add',
  edit='/busOutsourcingPurchaseReturn/edit',
  deleteOne = '/busOutsourcingPurchaseReturn/delete',
  approved = '/busOutsourcingPurchaseReturn/approved',
  counteraudit = '/busOutsourcingPurchaseReturn/counteraudit',
  deleteBatch = '/busOutsourcingPurchaseReturn/deleteBatch',
  importExcel = '/busOutsourcingPurchaseReturn/importExcel',
  exportXls = '/busOutsourcingPurchaseReturn/exportXls',
  busPurchaseReceiveItemList = '/busOutsourcingPurchaseReturn/queryBusOutsourcingPurchaseReturnItemByMainId',
  currencyList = '/base/currency/list',
  supplierlist = '/base/supplier/list',
  taxList = '/base/basMixTaxes/list',
  paymentConditionList = '/base/paymentCondition/list',
  materialList = '/base/material/list',
  warehouseList = '/base/basWarehouse/list',
  addBusPurchaseOrderItem ='/business/busPurchaseOrder/addBusPurchaseOrderItem',
  editBusPurchaseOrderItem ='/business/busPurchaseOrder/editBusPurchaseOrderItem'
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 查询子表数据
 * @param params
 */
export const busPurchaseReceiveItemList = Api.busPurchaseReceiveItemList;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});
/**
 * 料品接口
 * @param params
 */
 export const materialList = (params) =>
 defHttp.get({url: Api.materialList, params});  
/**
 * 供应商接口
 * @param params
 */
 export const supplierlist = (params) =>
 defHttp.get({url: Api.supplierlist, params});
 /**
 * 税额接口
 * @param params
 */
  export const taxList = (params) =>
  defHttp.get({url: Api.taxList, params});
   /**
 *条件接口
 * @param params
 */
    export const paymentConditionList = (params) =>
    defHttp.get({url: Api.paymentConditionList, params});     
  /**
 * 币种接口
 * @param params
 */
export const currencyList = (params) =>
defHttp.get({ url: Api.currencyList, params });
/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 采购单-反审核
 */
 export const counteraudit = (params,handleSuccess) => {
  return defHttp.get({url: Api.counteraudit, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 采购单-审核
 */
 export const approved = (params,handleSuccess) => {
  return defHttp.get({url: Api.approved, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新子表
 * @param params
 */
export const saveOrUpdateItem = (params, isUpdate) => {
  let url = isUpdate ? Api.editBusPurchaseOrderItem : Api.addBusPurchaseOrderItem;
  return defHttp.post({url: url, params});
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
